package ch.bfh.mobicomp;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.util.Log;
import android.widget.Toast;

public class RecoveryAlarmManager extends BroadcastReceiver{

	public static final String START_SODA_RECOVERY = "START_SODA_RECOVERY";
	private long triggerAtTime;

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		
		 PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
         PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
         wl.acquire();

         //Send Recovery Broadcast
         context.sendBroadcast(new Intent(START_SODA_RECOVERY));
 
         Toast.makeText(context, "Alarm !!!!!!!!!!", Toast.LENGTH_LONG).show(); // For example

         wl.release();
		
	}
	
	public void startRecovery(Context context, long starttimeInMs){
		
		AlarmManager am = (AlarmManager)context.getSystemService (Context.ALARM_SERVICE);
		Intent i = new Intent(context, RecoveryAlarmManager.class);
		
		PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
	
		am.set(AlarmManager.RTC_WAKEUP, starttimeInMs, pi);
		
		
	}

}
